﻿using System;
using System.Data;
using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client;
using System.Web;
using System.Web.Caching;


using LMD.Constant;
using LMD.Lib.Oracle;

namespace Cached
{
    /// <summary>
    /// Summary description for QuestionTypeTable
    /// </summary>
    public class QuestionTypeTable : CacheAbstraction
    {
        public DataTable GetQuestion()
        {
            return GetQuestion(false);
        }
        public DataTable GetQuestion(bool bForceRefresh)
        {
            String sxCacheKey = KCache.P_QUESTION_TYPE;

            if(bForceRefresh)
            {
                HttpRuntime.Cache.Remove(sxCacheKey);
            }

            if (HttpRuntime.Cache[sxCacheKey] == null)
            {
                DBLib dbl = new DBLib();

                String sxQuery =
                @"
                select
                    P1.P_QUESTION_TYPE_ID,
                    P1.CODE, 
                    P2.CODE CODE_TYPE, 
                    P2.P_INPUT_CONTROL_TYPE_ID,
                    p1.QUESTION_INDEX,
                    p1.IS_MANDATORY
                from
                    P_QUESTION_TYPE p1
                left join
                    P_INPUT_CONTROL_TYPE p2
                on
                    P1.P_INPUT_CONTROL_TYPE_ID = P2.P_INPUT_CONTROL_TYPE_ID
                where
                   p1.VALID_TO is null 
                order by P1.QUESTION_INDEX asc";

                DataTable dt = dbl.GetDataTable(sxQuery);

                AddToCache(sxCacheKey, dt, CacheType.Daily);
                
            }
            return (DataTable)HttpRuntime.Cache[sxCacheKey];
        }        

        public override String GetCacheFilename()
        {
            return KCache.Filename.PARAMETER_TABLE;
        }
    }
}